package com.kittlen.managementSystem.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.kittlen.managementSystem.entity.Coach;
import com.kittlen.managementSystem.entity.MySqlLimit;
import com.kittlen.managementSystem.entity.Result;
import com.kittlen.managementSystem.entity.Student;
import com.kittlen.managementSystem.service.ICoachService;
import com.kittlen.managementSystem.service.ICountService;
import com.kittlen.managementSystem.service.IStudentService;
import com.kittlen.managementSystem.service.IVehicleService;
import com.kittlen.managementSystem.utils.Md5;
import com.kittlen.managementSystem.utils.ObjectUtil;
import com.kittlen.managementSystem.utils.TimeUtil;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 统计 前端控制器
 * </p>
 *
 * @author kittlen
 * @since 2021-01-26
 */
@RestController
@RequestMapping("/count")
public class CountController {

    @Resource
    ICoachService iCoachService;//教练

    @Resource
    IVehicleService iVehicleService;//车辆

    @Resource
    IStudentService iStudentService;//学员

    @Resource
    ICountService iCountService;//统计

    @RequestMapping("/countAll")
    public Result countAll(){
        Result result=new Result();
        int coachCount=iCoachService.count(new QueryWrapper<Coach>().eq("is_end","0"));
        int studentCount=iStudentService.count(new QueryWrapper<Student>().eq("is_end","0"));
        int vehicleCount=iVehicleService.count();
        Map<String,Integer> map=new HashMap<String, Integer>();
        map.put("coachCount",coachCount);
        map.put("studentCount",studentCount);
        map.put("vehicleCount",vehicleCount);
        result.setData(map);
        return result;
    }

    @RequestMapping("countByStudent")
    public Result countByStudent(){
        Result result=new Result();
        Map<String,Integer> map=iCountService.countByStudent();
        result.setData(map);
        return result;
    }

    @RequestMapping("countByCoach")
    public Result countByCoach(){
        Result result=new Result();
        Map<String,Integer> map=iCountService.countByCoach();
        result.setData(map);
        return result;
    }

    @RequestMapping("countByVehicle")
    public Result countByVehicle(){
        Result result=new Result();
        Map<String,Integer> map=iCountService.countByVehicle();
        result.setData(map);
        return result;
    }

}
